/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package xperiment.metaphor.model.entity;

import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import xperiment.metaphor.model.DomainObject;

/**
 * The authorization events that occur when users are permitted / denied access
 * to resources.
 * @author Mark Ashworth <javameme@gmail.com>
 * @version 1.0.0
 * @since 1.0.0
 */
//@Entity
//@Table(name="authorization_event")
public class AuthorizationEvent extends DomainObject {
    
    /* The unique database id for the object */
    //@Id @GeneratedValue(strategy=GenerationType.AUTO)
    //@Column(name = "authorization_event_id", unique = true, nullable = false)
    private Long id = null;
    
    //@Column(name="event_time", nullable=true)
    private Date eventTime;
    
    /* The user name for which the authorization event was generated */
    //@Column(name="user_name", unique=false, nullable=false, length=25)
    private String userName;
    
    /* The status of the event */
    //@Column(name="status", unique=false, nullable=true, length=25)
    private String status;
    
    /* The source of the authorization event */
    //@Column(name="source", unique=false, nullable=true, length=1096)
    private String source;
    
    /* The security configuration attributes */
    //@Column(name="configuration", unique=false, nullable=true, length=4096)
    private String configuration;
    
    /* Authorization exception */
    //@Column(name="exception", unique=false, nullable=true, length=4096)
    private String exception;
    
    /** Whether the user is enabled */
    //@Column(name = "enabled", nullable=true)
    private boolean enabled = true;
    
    /**
     * Default constructor
     */
    public AuthorizationEvent() {
        super();
    }

	public Long getId() {
		return id;
	}
    
    /**
     * The user name for which the authorization event was generated
     * @return String
     */
    public String getUserName() {
        return userName;
    }

    /**
     * The user name for which the authorization event was generated
     * @param userName The new value
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    /**
     * The status of the event, typically FAILED, SUCCESS
     * @return String
     */
    public String getStatus() {
        return status;
    }

    /**
     * The status of the event, typically FAILED, SUCCESS
     * @param status The new value
     */
    public void setStatus(String status) {
        this.status = status;
    }
    
    /**
     * The source of the authorization event
     * @return String
     */
    public String getSource() {
        return source;
    }

    /**
     * The source of the authorization event
     * @param source The new value
     */
    public void setSource(String source) {
        this.source = source;
    }
    
    /**
     * The security configuration attributes
     * @return String
     */
    public String getConfiguration() {
        return configuration;
    }

    /**
     * The security configuration attributes
     * @param configuration The new value
     */
    public void setConfiguration(String configuration) {
        this.configuration = configuration;
    }

    /**
     * The exception that caused the authentication event
     * @return String
     */
    public String getException() {
        return exception;
    }

    /**
     * The exception that caused the authentication event
     * @param exception The new value
     */
    public void setException(String exception) {
        this.exception = exception;
    }
    
    /**
     * The time of the authorization event
     * @return Date
     */
    public Date getEventTime() {
        return eventTime;
    }

    /**
     * The time of the authorization event
     * @param eventTime The new value
     */
    public void setEventTime(Date eventTime) {
        this.eventTime = eventTime;
    }

    /**
     * Whether the authorization event is enabled
     * @return boolean
     */
    public boolean isEnabled() {
        return this.enabled;
    }
    
    /**
     * Whether the authorization event is enabled
     * @param enabled The new value
     */
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    
    @Override
    public boolean equals(Object obj) {
        
        if (obj == null) { return false; }
        if (obj == this) { return true; }
        if (obj.getClass() != getClass()) {
            return false;
        }
        AuthorizationEvent rhs = (AuthorizationEvent) obj;
        return new EqualsBuilder()
            .append(this.eventTime, rhs.getEventTime())
            .append(this.userName, rhs.getUserName())
            .append(this.status, rhs.getStatus())
            .append(this.source, rhs.getSource())
            .append(this.configuration, rhs.getConfiguration())
            .append(this.exception, rhs.getException())
            .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 41)
                .append(this.eventTime)
                .append(this.userName)
                .append(this.status)
                .append(this.source)
                .append(this.configuration)
                .append(this.exception).toHashCode();
    }
}
